import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;

/**
 * Created whit IntelliJ IDEA.
 * Description：
 * User：ZHONGCHEN
 * Date:2022-05-04
 * Time:22:24
 */
//1823. 找出游戏的获胜者
public class TestDemo {
    public int findTheWinner(int n, int k) {
        Deque<Integer> queue = new ArrayDeque<>();
        for (int i = 1; i <= n; i++) {
            queue.add(i);
        }
        while (queue.size() > 1) {
            for (int i = 1; i <= k; i++) {
                if (i == k){
                    queue.poll();
                }else {
                    queue.addLast(queue.poll());
                }
            }
        }
        return queue.poll();
    }
}
